/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaModificarAcontecimiento.java
 *
 * Created on 14-may-2012, 12:12:18
 */
package gui;

import ClasesAModificar.AcontecimientoModificar;
import javax.swing.JOptionPane;
import src.FuncionesModificar;

/**
 *
 * @author usuario_local
 */
public class VentanaModificarAcontecimiento extends javax.swing.JFrame {

    int elem;
    VentanaModificar vm;
    
    /** Creates new form VentanaModificarAcontecimiento */
    public VentanaModificarAcontecimiento(int elem, VentanaModificar vm,AcontecimientoModificar AM) {
        this.elem = elem;
        this.vm = vm;
        initComponents();
        inicializaContenido(AM);
        this.AM = AM;
    }
    
    private void inicializaContenido(AcontecimientoModificar AM)
    {
        jTextField_vacDescripcion.setText(AM.getDescripcion());
        jTextField_vacFechaCom.setText(String.valueOf(AM.getFIni()));
        jTextField_vacFechaFin.setText(String.valueOf(AM.getFFiN()));
        jTextField_vacNombre.setText(AM.getNombre());
    }

        private boolean comprobar(){
        String mensaje = "";
        boolean resultado = false;
        
        if (this.jTextField_vacNombre.getText().equals(""))
            mensaje += "Por favor rellene el campo de nombre\n\n";
        if (this.jTextField_vacDescripcion.getText().equals(""))
            mensaje += "Por favor rellene el campo de descripción\n\n";
        if(!mensaje.equals(""))
            JOptionPane.showMessageDialog(null, mensaje);
        else
            resultado = true;
        
        try{
            Integer.parseInt(this.jTextField_vacFechaCom.getText());
            Integer.parseInt(this.jTextField_vacFechaFin.getText());
            if(this.jTextField_vacFechaCom.getText().length() != 8 || this.jTextField_vacFechaFin.getText().length() != 8)
                throw new Exception();
            
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Por favor rellene las fechas de la siguiente manera:\n"
                    + "ej. 20120101 siendo los 4 primeros numeros el año, los dos siguientes el mes\n"
                    + "y los dos ultimos el día\n\n");
            resultado = false;
        }
              
        return resultado;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel_vacNombre = new javax.swing.JLabel();
        jTextField_vacNombre = new javax.swing.JTextField();
        jLabel_vacDescripcion = new javax.swing.JLabel();
        jTextField_vacDescripcion = new javax.swing.JTextField();
        jLabel_vacFechaCom = new javax.swing.JLabel();
        jTextField_vacFechaCom = new javax.swing.JTextField();
        jLabel_vacFechaFin = new javax.swing.JLabel();
        jTextField_vacFechaFin = new javax.swing.JTextField();
        jButton_VMAModifRelFichero = new javax.swing.JButton();
        jButton_vacTerminar = new javax.swing.JButton();
        jButton_VMAEliminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel_vacNombre.setText("Nombre");

        jLabel_vacDescripcion.setText("Descripcion");

        jLabel_vacFechaCom.setText("Fecha de Comienzo");

        jLabel_vacFechaFin.setText("Fecha de Finalizacion");

        jButton_VMAModifRelFichero.setText("Rel. Ficheros");
        jButton_VMAModifRelFichero.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_VMAModifRelFicheroMouseClicked(evt);
            }
        });

        jButton_vacTerminar.setText("Terminar");
        jButton_vacTerminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vacTerminarMouseClicked(evt);
            }
        });

        jButton_VMAEliminar.setText("Eliminar");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vacNombre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vacNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vacDescripcion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vacDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vacFechaFin)
                    .addComponent(jLabel_vacFechaCom))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_vacFechaCom, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                    .addComponent(jTextField_vacFechaFin, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 285, Short.MAX_VALUE)
                .addComponent(jButton_VMAModifRelFichero))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(125, 125, 125)
                .addComponent(jButton_VMAEliminar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_vacTerminar)
                .addContainerGap(105, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vacNombre)
                    .addComponent(jTextField_vacNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vacDescripcion)
                    .addComponent(jTextField_vacDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vacFechaCom)
                    .addComponent(jTextField_vacFechaCom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vacFechaFin)
                    .addComponent(jTextField_vacFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_VMAModifRelFichero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_vacTerminar)
                    .addComponent(jButton_VMAEliminar))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton_vacTerminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vacTerminarMouseClicked
// TODO add your handling code here:
    if(comprobar()){
        vm.setVisible(true);
        this.setVisible(false);

        AM.setDescripcion(jTextField_vacDescripcion.getText());
        AM.setFIni(Integer.valueOf(jTextField_vacFechaCom.getText()));
        AM.setFFiN(Integer.valueOf(jTextField_vacFechaFin.getText()));
        AM.setNombre(jTextField_vacNombre.getText());

        FuncionesModificar.modificarAcontecimiento(AM);
        this.dispose();
    }
}//GEN-LAST:event_jButton_vacTerminarMouseClicked

private void jButton_VMAModifRelFicheroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_VMAModifRelFicheroMouseClicked
// TODO add your handling code here:
    VentanaModificarRelaciones vmr = new VentanaModificarRelaciones(4,this,AM.getListaFicheros(),AM.getIdAcontecimiento());
    vmr.setVisible(true);
    this.setVisible(false);
}//GEN-LAST:event_jButton_VMAModifRelFicheroMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_VMAEliminar;
    private javax.swing.JButton jButton_VMAModifRelFichero;
    private javax.swing.JButton jButton_vacTerminar;
    private javax.swing.JLabel jLabel_vacDescripcion;
    private javax.swing.JLabel jLabel_vacFechaCom;
    private javax.swing.JLabel jLabel_vacFechaFin;
    private javax.swing.JLabel jLabel_vacNombre;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField_vacDescripcion;
    private javax.swing.JTextField jTextField_vacFechaCom;
    private javax.swing.JTextField jTextField_vacFechaFin;
    private javax.swing.JTextField jTextField_vacNombre;
    // End of variables declaration//GEN-END:variables
    private AcontecimientoModificar AM;
}
